package com.leps.nq.tx.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.leps.nq.tx.entity.PumpEffectivePoint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
@ApiModel
public class PumpDataVo {
    @ApiModelProperty("泵ID")
    private int pumpId;
    @ApiModelProperty("泵实际点位")
    private List<PumpEffectivePoint> pumpEffectivePoints;
    @ApiModelProperty("从PLC读取的数据列表形式")
    private List<Object> dataList;
    @ApiModelProperty("从PLC读取的数据键值形式")
    private Map<String, Object> dataMap;
    // =================== 业务解析后的数据 ==================
    @ApiModelProperty("泵的开关状态(0=关, 1=开)")
    private int running;
    @ApiModelProperty("泵开设定值（Min）")
    private int openSetupMinutes;
    @ApiModelProperty("泵关设定值（Min）")
    private int closeSetupMinutes;
    @ApiModelProperty("泵故障(1=故障,0=正常)")
    private int broken;
    @ApiModelProperty("泵开实时值（Min）")
    private int openRealMinutes;
    @ApiModelProperty("泵关实时值（Min）")
    private int closeRealMinutes;
    @ApiModelProperty("实时液位")
    private int liquidLevel;
    @ApiModelProperty("实时压力")
    private int pressure;


    @JsonIgnore
    public double getRatioPressure() {
        int ratio = this.pumpEffectivePoints.get(9).getRatio();
        return valueAfterRatio(this.pressure, ratio);
    }


    @JsonIgnore
    public double getRatioLiquidLevel() {
        int ratio = this.pumpEffectivePoints.get(8).getRatio();
        return valueAfterRatio(this.liquidLevel, ratio);
    }

    @ApiModelProperty("除以倍数后的实时液位(保留两位小数)")
    public String getRatioLiquidLevelStr() {
        return String.format("%.2f", getRatioLiquidLevel());
    }

    @ApiModelProperty("除以倍数后的实时压力(保留两位小数)")
    public String getRatioPressureStr() {
        return String.format("%.2f", getRatioPressure());
    }

    public static double valueAfterRatio(double dataValue, int radio) {
        return (dataValue / radio);
    }
}
